package com.huike.web.controller.system;

import com.huike.clues.domain.SysOperLog;
import com.huike.clues.service.ISysOperLogService;
import com.huike.common.annotation.Log;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.enums.BusinessType;
import com.huike.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author EthanRuins
 * @date 2023/7/13
 * @apiNote
 */
@RestController
@RequestMapping("/monitor/operlog")
@Api(tags = "操作日志记录相关接口")
@AllArgsConstructor
public class SysOperLogController extends BaseController {
    private final ISysOperLogService operLogService;

    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询操作日志列表")
    public TableDataInfo<List<SysOperLog>> getList(SysOperLog sysOperLog) {
        startPage();
        List<SysOperLog> list = operLogService.getList(sysOperLog);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
    @GetMapping("/export")
    @ApiOperation(value = "操作日志导出")
    @Log(title = "操作日志导出", businessType = BusinessType.EXPORT)
    public AjaxResult<Object> export(SysOperLog sysOperLog) {
        List<SysOperLog> list = operLogService.getList(sysOperLog);
        ExcelUtil<SysOperLog> excelUtil = new ExcelUtil<>(SysOperLog.class);
        return excelUtil.exportExcel(list, "操作日志");
    }

    @PreAuthorize("@ss.hasPermi('monitor:operlog:delete')")
    @DeleteMapping("/{operIds}")
    @ApiOperation(value = "操作日志删除")
    public AjaxResult<Integer> delete(@PathVariable Long[] operIds) {
        return toAjax(operLogService.deleteByIds(operIds));
    }

    @PreAuthorize("@ss.hasPermi('monitor:operlog:delete')")
    @DeleteMapping("/clean")
    @ApiOperation(value = "清空操作日志")
    public AjaxResult<Object> cleanOperLog() {
        operLogService.cleanOperLog();
        return AjaxResult.success();
    }
}
